/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import BO.Controller;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Ymmot
 */
public class SendprivatemessageBean {

    private String targetUsername;
    private String title;
    private String content;
    private Controller controller;
    private HttpSession session;
    
    public SendprivatemessageBean() {
        controller = new Controller();
        session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTargetUsername() {
        return targetUsername;
    }

    public void setTargetUsername(String targetUsername) {
        this.targetUsername = targetUsername;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    
    public String submitPrivateMessage() {
        UserView u = (UserView) session.getAttribute("user");
        boolean status = controller.submitPrivateMessage(u.getId(), targetUsername, title, content);
        if(status)
            return "pmSend";
        return "pmFail";
    }
}
